package xue;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServiceSocket {
    public static void main(String[] args) throws IOException {
        ServerSocket sercice=new ServerSocket(888);
        Socket socket=sercice.accept();
        System.out.println("2");
        File f=new File("D:\\project\\ch05\\src\\main\\java\\xue\\a.txt");
        BufferedInputStream in=new BufferedInputStream(socket.getInputStream());
        BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(f));
        BufferedOutputStream out2=new BufferedOutputStream(socket.getOutputStream());
        System.out.println("1");
        byte[] b=new byte[10];
        String s=null;
        String s1=null;

        while ( in.read(b)!=-1){

//            System.out.println(new String(b,"UTF-8"));
            out.write(b);
            out.flush();
            s=new String(b,"utf-8");
            System.out.println(s);
            System.out.println(s1);

        }

        System.out.println("3");
        String str="ok";
        byte[] b2=str.getBytes("UTF-8");
        out2.write(b2);
        out2.flush();
        socket.shutdownOutput();
    }
}
